import bpy
import ctypes
from bpy.types import Panel, Menu

from global_data.global_enum import *




class C_材质列表_UL_example(bpy.types.UIList):
	def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
		ob = data
		槽 = item
		#if item.bl_idname == 'C_ShaderNodeTree':
		layout.prop(item, "name", icon_value=icon)


class C_着色列表_UL_example(bpy.types.UIList):
	def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
		ob = data
		槽 = item
		#if item.bl_idname == 'C_ShaderNodeTree':
		layout.prop(item, "name", icon_value=icon)




class C_材质预览Panel:
	bl_space_type = 'PROPERTIES'
	bl_region_type = 'WINDOW'
	bl_context = "material"



class C_材质预览面板(C_材质预览Panel, Panel):
	bl_label = "Preview"
	bl_context = "material"
	bl_options = {'DEFAULT_CLOSED'}

	@classmethod
	def poll(cls, context):
		return context.material and (context.scene.render.engine in COMPAT_ENGINES)

	def draw(self, context):
		self.layout.template_preview(context.material)



class C_当前材质面板(C_材质预览Panel, Panel):
	bl_label = '场景渲染层'

	@classmethod
	def poll(cls, context):
		scene = context.scene
		return (scene.render.engine in COMPAT_ENGINES)

	def draw(self, context):
		layout = self.layout

		scene = context.scene
		rd = scene.render

		ob = context.object
		if ob:
			row = layout.row()
			row.template_list("MATERIAL_UL_matslots", "", ob, "material_slots", ob, "active_material_index", rows=4)

			col = row.column(align=True)
			col.operator("object.material_slot_add", icon='ZOOMIN', text="")
			col.operator("object.material_slot_remove", icon='ZOOMOUT', text="")
			



			split = layout.split(percentage=0.5)
			split.template_ID(ob, "active_material", new="material.new")
			row = split.row()
			row.template_ID(bpy.data, "node_groups")

			row = layout.row()
			
			#row.props_enum(bpy.data, "materials")
			#row.template_list('C_材质列表_UL_example', "", bpy.data, "materials", bpy.data.materials[0], "active_texture_index", type='COMPACT')
			#row.template_ID('C_材质列表_UL_example', "", bpy.data, "materials", bpy.data.materials[0], "active_texture_index", type='COMPACT')



		'''row = layout.row()
		col = row.column()
		col.template_list("RENDERLAYER_UL_renderlayers", "", rd, "layers", rd.layers, "active_index", rows=2)
		
		col = row.column()
		sub = col.column(align=True)
		sub.operator("scene.render_layer_add", icon='ZOOMIN', text="")
		sub.operator("scene.render_layer_remove", icon='ZOOMOUT', text="")
		col.prop(rd, "use_single_layer", icon_only=True)

		顶图层 = rd.layers[scene.active_layer]
		图层大小横向布局 = layout.column()
		图层大小横向布局.prop(顶图层, "prop_单元大小", text='视距', icon='SORTSIZE')

		引擎场景图层数量 = dllAPI.flexCAPI.f_getScene图层数量(ctypes.c_wchar_p(scene.name))
		ico = 'SORTSIZE'
		if 引擎场景图层数量 < len(rd.layers) :
			ico = 'ERROR'
		图层大小横向布局 = layout.column()
		图层大小横向布局.operator("scene.game_scene_layer_update", icon=ico)'''









材质面板注册类 = (
	#C_材质预览面板,
	C_当前材质面板,

	C_材质列表_UL_example,
	C_着色列表_UL_example,
)


def register():

	for cls in 材质面板注册类:
		bpy.utils.register_class(cls)

def unregister():
	
	for cls in 材质面板注册类:
		bpy.utils.unregister_class(cls)

